public class Solution33 {
    public int search(int[] nums, int target) {
        int l=0,r=nums.length-1;
        while (l<=r){
            int mid=(l+r)/2;
            if (nums[mid]==target){
                return mid;
            }
            if (nums[mid]>nums[nums.length-1] && target>nums[mid] || nums[mid]>nums[nums.length-1] && target<=nums[nums.length-1]
                || target<=nums[nums.length-1] && target>nums[mid]){
                l=mid+1;
            }else{
                r=mid-1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution33().search(new int[]{4,5,6,7,0,1,2},0));
    }
}
